/**
 define('ErrCode_Normal', 0000);
 define('ErrCode_Distance', 0001);
 define('ErrCode_Maintain', 0002);

 define('ErrCode_Dialog', 3000);
 define('ErrCode_Toast', 3001);
 define('ErrCode_Sign', 3002);
 define('ErrCode_Other', 3003);

 define('ErrMsg_Normal', '正常');
 define('ErrMsg_Distance', '该账号已下线或异地登录');
 define('ErrMsg_Maintain', '系统维护中');

 define('ErrMsg_Dialog', '弹窗错误');
 define('ErrMsg_Toast', 'Toast错误');
 define('ErrMsg_Sign', '校验数据错误');
 define('ErrMsg_Other', '其他错误');

 define('ErrMsg_Sys', '系统繁忙，请稍后再试！');
 */
var ErrCode_Normal = 0;
var ErrCode_Distance = 1;
var ErrCode_Maintan = 2;

var ErrCode_Dialog = 3000;
var ErrCode_Toast = 3001;
var ErrCode_Sign = 3002;
var ErrCode_Other = 3003;

var LOG_DEBUG = true;

var global = {

    // 提交数据
    post: function (url, field, success, error, complete) {
        $.ajax({
            type: "POST",
            url: url,
            dataType: "json",
            data: field,
            success: success,
            complete: complete,
            error: error
        });
    },

    get: function (url, field, success, error, complete) {
        $.ajax({
            type: "GET",
            url: url,
            dataType: "json",
            data: field,
            success: success,
            complete: complete,
            error: error
        });
    },

    log: function (title, content) {
        if (LOG_DEBUG) {
            console.log('---------------' + title + '---------------');
            console.log(content);
            console.log('------------------------------');
        }
    },

    add: function (field, success, error, complete) {
        post('/index.php/superadmin/Event/Add', field, success, error, complete);
    },

    edit: function (field, success, error, complete) {
        post('/index.php/superadmin/Event/Edit', field, success, error, complete);
    },

    delete: function (field, success, error, complete) {
        post('/index.php/superadmin/Event/Delete', field, success, error, complete);
    }
}

function mb_OnMessage(msg) {
    switch (msg['code']) {
        case ErrCode_Distance:
            layer.msg(msg['msg']);
            break;
        case ErrCode_Maintan:
            layer.msg('系统维护中');
            break;
        case ErrCode_Dialog:
            var data = msg['data'];
            layer.open({
                title: data.title
                , content: data.content
            });
            break;
        case ErrCode_Toast:
            layer.msg(msg['msg']);
            break;
        case ErrCode_Sign:
            layer.msg('数据校验错误');
            break;
        case ErrCode_Other:
            layer.msg(msg['msg']);
            break;
        default:
            break;
    }
}

//设置cookie
function mb_SetCookie(name, value, day) {
    var date = new Date();
    date.setDate(date.getDate() + day);
    console.log(date);
    document.cookie = name + '=' + value + ';expires=' + date;
};

//获取cookie
function mb_GetCookie(name) {
    var reg = RegExp(name + '=([^;]+)');
    var arr = document.cookie.match(reg);
    if (arr) {
        return arr[1];
    } else {
        return '';
    }
};

//删除cookie
function mb_DelCookie(name) {
    setCookie(name, null, -1);
};

function mb_GetFileIcon(FileUrl) {
    var FileArr = FileUrl.split("/");
    var FileName = FileArr[(FileArr.length - 1)];
    var FileTemp = FileName.split(".");
    if(FileTemp.length == 2){
        var Suffix = FileTemp[1];
        if(Suffix == 'doc' || Suffix == 'docx')return "/uploads/images/icon_word.png";
        else if(Suffix == 'ppt' || Suffix == 'pptx')return "/uploads/images/icon_ppt.png";
        else if(Suffix == 'xls' || Suffix == 'xlsx')return "/uploads/images/icon_excel.png";
        else if(Suffix == 'jpg' || Suffix == 'jpeg' || Suffix == 'png' || Suffix == 'bmp')return "/uploads/images/icon_jpg.png";
        else return "/uploads/images/icon_txt.png";
    } else {
        return "/uploads/images/icon_txt.png";
    }
}

function mb_GetFileReviewUrl(FileUrl) {
    var FileArr = FileUrl.split("/");
    var FileName = FileArr[(FileArr.length - 1)];
    var FileTemp = FileName.split(".");
    if(FileTemp.length == 2){
        var Suffix = FileTemp[1];
        if(Suffix == 'doc' || Suffix == 'docx')return "https://view.officeapps.live.com/op/view.aspx?src="+FileUrl;
        else if(Suffix == 'ppt' || Suffix == 'pptx')return "https://view.officeapps.live.com/op/view.aspx?src="+FileUrl;
        else if(Suffix == 'xls' || Suffix == 'xlsx')return "https://view.officeapps.live.com/op/view.aspx?src="+FileUrl;
        else if(Suffix == 'jpg' || Suffix == 'jpeg' || Suffix == 'png' || Suffix == 'bmp')return "/uploads/images/icon_jpg.png";
        else return "/uploads/images/icon_txt.png";
    } else {
        return FileUrl;
    }
}